package com.goodving.guli.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.goodving.guli.R;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.DimPanelFragment;
import com.goodving.guli.bt.eventbus.EventPersonInfoUpdate;
import com.goodving.guli.bt.eventbus.EventUserInfoUpdate;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.ui.PickAdapter;
import com.goodving.guli.bt.utils.WeightUtil;
import com.goodving.guli.bt.weight.UserInfo;
import com.goodving.guli.bt.weight.UserInfoManager;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.utility.gulihardware.Constant;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;

import de.greenrobot.event.EventBus;
import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;

/**
 * Created by john on 2015/12/17.
 */
public class WeightPanelFragment extends DimPanelFragment { // dj
    private static final String f9962e;
    private static int f9963k;
    private PersonInfo f9964a;
    private UserInfo f9965b;
    private WheelView f9966c;
    private WheelView f9967d;
    private int f9968f;
    private int f9969g;
    private int f9970h;
    private float f9971i;
    private PickAdapter f9972j;

    static {
        f9962e = WeightPanelFragment.class.getSimpleName();
    }

    public WeightPanelFragment() {
        this.f9968f = 3;
        this.f9969g = Constant.at;
    }

    public static Fragment m14666a(int i) {
        f9963k = i;
        return new WeightPanelFragment();
    }

    private int m14668b() {
        return WeightUtil.m15718c(getActivity()) > Constant.at ? 9 : 0;
    }

    protected int inflateLayout() {
        return R.layout.fragment_person_info_setting_weight;
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (f9963k == -1) {
            this.f9964a = Keeper.readPersonInfo();
            this.f9971i = this.f9964a.weight;
            return;
        }
        this.f9965b = UserInfoManager.getInstance().getInfoByUid(f9963k);
        this.f9971i = this.f9965b.weight;
    }

    class dk implements OnWheelScrollListener {
        final /* synthetic */ WeightPanelFragment f9973a;

        dk(WeightPanelFragment djVar) {
            this.f9973a = djVar;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished (WheelView wheelView) { // m14672b
            GuliLog.tracePrintInfo(WeightPanelFragment.f9962e, "item " + wheelView.getRealCurrentItem());
            if (wheelView.getRealCurrentItem() == 631) {
                GuliLog.tracePrintInfo(WeightPanelFragment.f9962e, " should refresh month");
                PickAdapter dmVar = new PickAdapter(this.f9973a.getActivity(), 0, this.f9973a.m14668b(), this.f9973a.f9967d, this.f9973a.getResources().getColor(R.color.highlight), this.f9973a.getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
                dmVar.m14686a(19);
                this.f9973a.f9967d.setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(WeightUtil.m15698a(this.f9973a.getActivity().getApplicationContext(), Keeper.readPersonInfo().miliConfig.weightUnit), 25.123f).setViewAdapter(dmVar).setCurrentItem(0);
                return;
            }
            this.f9973a.f9967d.setViewAdapter(this.f9973a.f9972j);
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View onCreateView = super.onCreateView(layoutInflater, viewGroup, bundle);
        this.f9970h = Keeper.readPersonInfo().miliConfig.weightUnit;
        this.f9968f = (int) WeightUtil.m15706b(3.0f, this.f9970h);
        this.f9969g = (int) WeightUtil.m15706b((float) WeightUtil.m15718c(getActivity()), this.f9970h);
        this.f9966c = (WheelView) onCreateView.findViewById(R.id.info_weight_int_wheel);
        this.f9967d = (WheelView) onCreateView.findViewById(R.id.info_weight_decimal_wheel);
        WheelView a = this.f9966c.setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(C3657a.f18328f, 25.123f);
        a.setViewAdapter(new PickAdapter(getActivity(), this.f9968f, this.f9969g, this.f9966c, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1)).setCurrentItem(((int) WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit)) - ((int) WeightUtil.m15706b(3.0f, Keeper.readPersonInfo().miliConfig.weightUnit)));
        this.f9972j = new PickAdapter(getActivity(), 0, 9, this.f9966c, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
        this.f9972j.m14686a(19);
        if (WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit) < ((float) this.f9969g)) {
            GuliLog.tracePrintInfo(f9962e, " < max");
            GuliLog.tracePrintInfo(f9962e, " max weight: " + this.f9969g);
            this.f9967d.setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(WeightUtil.m15698a(getActivity().getApplicationContext(), Keeper.readPersonInfo().miliConfig.weightUnit), 25.123f).setViewAdapter(this.f9972j).setCurrentItem(((int) (WeightUtil.m15716c(WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit), 1) * 10.0f)) - (((int) WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit)) * 10));
            GuliLog.tracePrintInfo(f9962e, "raw " + this.f9971i);
            GuliLog.tracePrintInfo(f9962e, "to unit" + WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit));
            GuliLog.tracePrintInfo(f9962e, "raw*10 -> int " + ((int) (WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit) * 10.0f)));
            GuliLog.tracePrintInfo(f9962e, "raw -> int * 10" + (((int) WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit)) * 10));
        } else {
            GuliLog.tracePrintInfo(f9962e, " >= max");
            PickAdapter dmVar = new PickAdapter(getActivity(), 0, m14668b(), this.f9967d, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
            dmVar.m14686a(19);
            this.f9967d.setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(WeightUtil.m15698a(getActivity().getApplicationContext(), Keeper.readPersonInfo().miliConfig.weightUnit), 25.123f).setViewAdapter(dmVar).setCurrentItem(((int) (WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit) * 10.0f)) - (((int) WeightUtil.m15706b(this.f9971i, Keeper.readPersonInfo().miliConfig.weightUnit)) * 10));
        }
        this.f9966c.addScrollingListener(new dk(this));
        return onCreateView;
    }

    public void onDestroy() {
        super.onDestroy();
        C0668a.m8128a(getActivity(), C0668a.dY, C3657a.f18328f + this.f9971i);
    }

    public void onPause() {
        super.onPause();
        C0668a.m8141b(C0668a.f3568k);
    }

    public void onResume() {
        super.onResume();
        C0668a.m8133a(C0668a.f3568k);
    }

    protected void onRightButtonClicked() {
        this.mRightButton.setEnabled(false);
        float f;
        if (this.f9964a != null) {
            f = this.f9964a.weight;
            float f2 = (((float) this.f9966c.getRealCurrentItem()) + (((float) this.f9967d.getRealCurrentItem()) / 10.0f)) + ((float) ((int) WeightUtil.m15706b(3.0f, Keeper.readPersonInfo().miliConfig.weightUnit)));
            GuliLog.tracePrintInfo(f9962e, "currentItem " + this.f9966c.getRealCurrentItem() + " float " + (((float) this.f9967d.getRealCurrentItem()) / 10.0f) + " min " + ((int) WeightUtil.m15706b(3.0f, Keeper.readPersonInfo().miliConfig.weightUnit)));
            this.f9964a.weight = WeightUtil.m15689a(f2, Keeper.readPersonInfo().miliConfig.weightUnit);
            GuliLog.tracePrintInfo(f9962e, "weight_KG :" + f2 + ", setperson weight " + this.f9964a.weight + ", original weight:" + f + ", miliConfig.weight :" + Keeper.readPersonInfo().miliConfig.weightUnit);
            if (f == this.f9964a.weight) {
                dismiss();
                return;
            }
            this.f9964a.setNeedSyncServer(2);
            Keeper.keepPersonInfo(this.f9964a);
            EventBus.getDefault().post(new EventPersonInfoUpdate(null));
        } else {
            f = this.f9965b.weight;
            this.f9965b.weight = WeightUtil.m15689a((((float) this.f9966c.getRealCurrentItem()) + (((float) this.f9967d.getRealCurrentItem()) / 10.0f)) + 3.0f, Keeper.readPersonInfo().miliConfig.weightUnit);
            if (f == this.f9965b.weight) {
                dismiss();
                return;
            }
            EventBus.getDefault().post(new EventUserInfoUpdate(this.f9965b));
        }
        dismiss();
    }
}
